<?php

define('MANS_', true);

require (dirname(__FILE__) . '/includes/init.php');
//print_r($_SESSION);die();
 if(empty($_SESSION['tps']))
 {
		$_SESSION['tps']=1;
 }
$size = 18;
$start = $page*$size;
$index_act =  !empty($_REQUEST['index_act']) ? ($_REQUEST['index_act']) : 'goods';
$sort = !empty($_GET['sort']) ? $_GET['sort'] : 'desc';
if($index_act=='goods')
{
	//$order = !empty($_GET['order']) ? $_GET['order'] : 'sort desc,add_time';
	$order = !empty($_GET['order']) ? $_GET['order'] : 'L';

}

else
{
	$order = !empty($_GET['order']) ? $_GET['order'] : 'add_time';

}

$order = preg_replace("/-/"," ",$order);
$descs = !empty($_GET['descs']) ? $_GET['descs'] : '';

$kw = !empty($_GET['kw']) ? $_GET['kw'] : '';

$type_id = !empty($_GET['type_id']) ? intval($_GET['type_id']) : 0;
$url = "";
$log_table = !empty($_GET['log_table']) ? ($_GET['log_table']) : 'review';

$log_type = !empty($_GET['log_type']) ? intval($_GET['log_type']) : '3';

if($order=='haoping_per')
	$order = 'haoping_per desc,goods_number ';

if(isset($_GET['cat_type']))
{
	$_SESSION['cat_type'] = intval($_GET['cat_type']);
	setcookie('cat_type', intval($_GET['cat_type']), time() + 86400 * 365, '/');

}


if($cat_type==1)
{
	$order = !empty($_GET['order']) ? $_GET['order'] : 'goods_number';
}





if(!$sm->isCached('index.htm',$cache_id))
{

	$position = $Main->position();

	$Main->assigns($position);

	//$sm->assign('to_day', $Goods->toDayGoods()); // 今日排行
	//$sm->assign('clicks', $Goods->clickTop()); // 点击排行

	if($Main->isMobileDevice())
	{
		$f = array('bracelet','necklace','ring');
		$fea_goods = $Goods->featureGoods($f,10);
		$sm->assign('fea_goods',	$fea_goods);
	}
	else
	{

		$kwd = "";
		$type_ids = "";
		//print_r($logs);die();
		if($index_act=='cat')
		{
			$cat_types  = $Other->inCatTypes($cat_type);
			if($kw)
				$kwd = " and (cat_name like '%$kw%')";
			if($type_id)
				$type_ids = "and type_id=$type_id";
			//不调用积分商品的店铺
			$where = "where is_show>=1 $kwd $type_ids and cat_id!=".JF_MALL_ID." and type in($cat_types) order by $order $sort ";

			$count = $Main->counts("select count(*) from category $where");
			$url = "index.php?index_act=cat&order=$order&kw=$kw&type_id=$type_id&sort=$sort";
			$pager = $Main->pager($count,$size,$url);
			$cat = $Cate->categoryAll($start,$size,$where);
			$Other->updateCatRank($cat,$order,$start);

			$sm->assign('pagers',	$pager);
			$sm->assign('cat',	$cat);


		}
		elseif($index_act=='cat_log')
		{

			$Other->logFilter($log_table,$log_type,$kw,$kwd,$start,$size);

		}
		else
		{
			$descss = '';
			if($kw)
				$kwd = " and (goods_name like '%$kw%' or keywords like '%$kw%' or goods_desc like '%$kw%' or descs like '%$kw%' or mag_names like '%$kw%' )";
			if($type_id)
				$type_ids = "and relates=$type_id";
			if($descs)
				$descss = " and descs like '%$descs%'";
			//不调用积分商品的商品

			$where = " where cat_id!=".JF_MALL_ID." and cat_type=$cat_type $kwd $type_ids $descss order by $order $sort";

			$goods_list = $Goods->goodsList($start,$size,$where,' ,download, haoping,style_name,rank,cat_type,goods_weight');

			$Other->updateGoodsRank($goods_list,$order,$start);
			$sm->assign('goods_list',	$goods_list);
			//print_r($goods_list);die();
			$count = $Main->counts("select count(*) from goods $where");
			$url = 'index.php?index_act=goods&order='.$order.'&sort='.$sort.'&kw='.$kw.'&type_id='.$type_id.'&descs='.$descs;
			$pager = $Main->pager($count,$size,$url);
			$sm->assign('pagers',	$pager);

			if($order=='goods_number')
			{
				$last = $goods_list = $Goods->goodsList(0,3,"where cat_id!=".JF_MALL_ID." and cat_type=$cat_type order by add_time desc");
				$sm->assign('last',$last);
			}


		}

	}
	if($cat_type==0)//区分小区精益 关键词，买点
	{
		$sm->assign('hot_keywords',	$Other->keywords(0,50,"where type=1 order by times desc"));
		$sm->assign('descs',	$Other->keywords(0,50,"where type=2 order by times desc"));
	}
	else
	{
		$sm->assign('hot_keywords',	$Other->keywords(0,50,"where type=3 order by times desc"));
		$sm->assign('descs',	$Other->keywords(0,50,"where type=4 order by times desc"));
	}

	$sm->assign('typeids',	$Other->typeids());
	$sm->assign('type_id',	$type_id);
	$Other->leftData($cat_type);
	$sm->assign('cat_type',	$cat_type);
	$sm->assign('order',	$order);
	$sm->assign('sort',	$sort);
	$sm->assign('log_table',	$log_table);
	$sm->assign('log_type',	$log_type);
	$sm->assign('kw',	$kw);
	$sm->assign('descss',	$descs);


	$url = preg_replace("/&sort=desc|&sort=asc/","",$url);
	@$sm->assign('url',	$url);
	//print_r($_COOKIE['recent_goods']);die();


	//print_r($GLOBALS['_CFG']);
	$sm->assign('index_act',	$index_act);
}



if ($no_style) {
	$sm->display("no_style.htm");
}
else
{


    $sm->display('index.htm',$cache_id);
}

?>
